<?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
 * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace Admin\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Admin\Form\UserForm;
class IndexController extends AbstractActionController
{
    public function indexAction()
    {        
        return array( 'welcome' => 'Hello Zend Framework 2.0 - By QHOnline.Info' );
    }
    
    public function aboutAction()
    {                                        
       $userTable = $this->getServiceLocator()->get('Admin\Model\UserTable');           
       return new ViewModel (array('users' => $userTable->fetchAll()));
    }
    
    public function addAction(){
        $request = $this->getRequest();
        if ($request->isPost()) {                         
            //$form->setInputFilter($sample->getInputFilter());
            //$form->setData($request->getPost());
 
            //if ($form->isValid()) {
                //SAVE TO DATABASE...
            //}
        }
         
        //return array( 'form' => $form );        
       
       //Truyền đối tượng UserForm vào đối tượng ViewModel
      // $viewModel  = new ViewModel(array('form' => $form));
       
       
       //Đư đối tượng ViewModel ra ngoài VIEW
       //return $viewModel;
    }


    public function editAction(){
        $id = (int) $this->params()->fromRoute('id', 0);        
        $userTable = $this->getServiceLocator()->get('Admin\Model\UserTable'); 
        $album = $userTable->loadById($id);       
        $userTable = $this->getServiceLocator()->get('Admin\Model\UserTable'); 
        return new ViewModel (array('users' => $userTable->loadById( $id )));
    }
    
    public function deleteAction($id){
        
    }
}
